package com.ljx.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.ljx.R;
import com.ljx.client.VodInterface;
import com.ljx.pojo.EduVideo;
import com.ljx.pojo.chapter.VideoVo;
import com.ljx.service.impl.EduVideoServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 课程视频 前端控制器
 * </p>
 *
 * @author 李加喜
 * @since 2020-09-25
 */
@Api(description = "小节的设置")
@RestController
@RequestMapping("/eduservice/video")
@CrossOrigin
public class EduVideoController {
    @Autowired
    private EduVideoServiceImpl eduVideoService;
    //注入VodClient
    @Autowired
    private VodInterface vodInterface;
    //添加小节
    @ApiOperation("小节的添加")
    @PostMapping("/addVideo")
    private R addVideo(@RequestBody EduVideo eduVideo) {
        eduVideoService.save(eduVideo);
        return R.ok();
    }
    //删除小节
    //ToDD 这个方法还需要完善 删除小节的时候还要删除视频
    //调用另外一个模块的删除视频的方法  需要使用SpringCloud
    //将edu模块最为消费者  将vod模块作为生产者  使用生产者调用消费者
    //也可以引入模块 但是引入之后就不是微服务了
    @DeleteMapping("/delVideo/{id}")
    private R deleteVideo(@PathVariable String id){
        String videoSourceId = eduVideoService.getById(id).getVideoSourceId();
        if (!StringUtils.isEmpty(videoSourceId)){
            vodInterface.delVdo(videoSourceId);
        }
        eduVideoService.removeById(id);
        //实现了删除小节同时删除视频的功能呢
        return R.ok();
    }
    //修改小节
    //查询小节
    @GetMapping("/getvideo/{videoId}")
    private R getVideo(@PathVariable String videoId){
        EduVideo eduVideo = eduVideoService.getById(videoId);
        return R.ok().data("video",eduVideo);
    }
    //实现具体的修改小节
    @ApiOperation("小节修改")
    @PostMapping("/updateVideo")
    public R updateVideo(@RequestBody EduVideo eduVideo){
        eduVideoService.updateById(eduVideo);
        return R.ok();
    }
}

